#include <iostream>
#include <bits/stdc++.h>

using namespace std;

typedef struct Node{
    int data;
    Node * next;
    Node *prior;
};

class List{
private:
    Node *head;
    int len;

public:
    List(): head(nullptr), len(0){}

    List(int d) {
        head = new Node[1];
        head -> data = d;
        head -> next = nullptr;
        head -> prior = nullptr;
    }
    ~List(){
        Node *p = head;
        while (p != nullptr) {
            Node *temp = p;
            p = p -> next;

            delete temp;
        }
        len = 0;
    }
    void init() {
        char ch;
        int d;
        Node *p1 = new Node[1];
        head = p1;
        while (cin >> ch) {          //ÎÊÌâ±£Áô
            if ( ch == '#') break;
            Node *p2 = new Node[1];
            p2 -> data = ch - '0';
            p2 -> next =nullptr;
            p2 -> prior = p1;
            p1 -> next = p2;
            len += 1;
            p1 = p2;
        }
    }

    int searchData(int index) {           // 0 -- head ; len- 1 -- lastOne
        if (index >= len) {
            printf("index 出错\n");;
            return -1;
        }
        Node *p = head;
        while (index--) {
            p = p -> next;
        }
        return p -> data;
    }
    Node *searchNode(int index) {
        if (index >= len) {
            printf("index 出错\n");;
            return nullptr;
        }
        Node *p = head;
        while (index--) {
            p = p -> next;
        }
        return p;
    }

    void insertAny(int data, int index) {           // -1 -- headBefore len ---- headEnd 0 --- len - 1 anferNode
        Node *p = searchNode(index);
        Node *p1 = new Node[1];
        p1 -> data = data;
        p1 -> next = p -> next;
        p1 -> prior = p;
        p -> next -> prior = p1;
        p -> next = p1;
        len += 1;
    }

    void delete_(int index) {           //  删除当前位置节点
        Node *p = searchNode(index);
        Node *temp = p;
        p -> next -> prior = p -> prior;
        p -> prior -> next = p -> next;

        delete temp;
        len -= 1;
    }

    int getLenth() { return len;}

    void modify(int index, int data) {
        Node *p = searchNode(index);
        p -> data = data;
    }

    void print() {
        Node *p = head -> next;
        while (p != nullptr) {
            cout << p -> data << " " ;
            p = p -> next;
        }
        cout << endl;
    }
};


int main(){
    ios::sync_with_stdio(false);
    List list1;
    list1.init();
    int data;
    int index;
    cin >> data >> index;
    list1.insertAny(data, index);
    list1.print();
    int d = list1.searchData(index);
    cout << d <<endl;
    int len = list1.getLenth();
    cout << len << endl;
    list1.modify(index, data);
    list1.print();
    list1.delete_(index);
    list1.print();
}
